<template>
  <!-- recommend 推荐 页面 -->
  <div class="recommend" ref="recommend">
    <scroll ref="scroll" class="recommend-content" :data="recommendList" :bounceTop="false">
      <div class="scroll-content">
        <div v-if="sliderList.length" class="slider-wrapper">
          <!-- 轮播图 -->
          <slider>
            <div v-for="(item, index) in sliderList" :key="index">
              <a :href="item.url">
                <img @load="loadImage" class="needsclick" :src="item.pic" />
              </a>
            </div>
          </slider>
        </div>

        <!-- 推荐歌单 -->
        <div class="recommend-list">
          <h1 class="list-title">热门歌单推荐</h1>
          <ul>
            <li @click="selectItem(item)" v-for="(item, index) in recommendList" class="item" :key="index">
              <div class="icon">
                <!-- <img width="60" height="60" :src="item.picUrl" /> -->
                <img width="60" height="60" v-lazy="item.picUrl + '?param=128y128'" />
              </div>
              <div class="text">
                <h2 class="name" v-html="item.name"></h2>
                <p class="desc" v-html="item.copywriter"></p>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <!-- loading -->
      <div class="loading-container" v-show="!recommendList.length">
        <loading></loading>
      </div>
    </scroll>

    <router-view></router-view>
  </div>
</template>
<script>
import { getSliderList, getRecommendList } from 'api/recommend';
import Slider from 'components/slider/slider';
import Scroll from 'components/scroll/scroll';
import Loading from 'components/loading/loading';
import { playlistMixin } from 'common/js/mixin';
import { mapMutations } from 'vuex';

export default {
  mixins: [playlistMixin],
  data() {
    return {
      sliderList: [],
      recommendList: [],
    };
  },
  created() {
    this._getSliderList();
    this._getRecommendList();
  },
  methods: {
    ...mapMutations(['setAlbum']),
    selectItem(item) {
      this.setAlbum({ id: item.id, name: item.name, avatar: item.picUrl });
      this.$router.push({ path: `/recommend/${item.id}` });
    },
    _getSliderList() {
      getSliderList().then((res) => {
        // console.log('res', res);
        this.sliderList = res.banners;
      });
    },
    _getRecommendList() {
      getRecommendList().then((res) => {
        // console.log('res', res);
        this.recommendList = res.result;
      });
    },
    loadImage() {
      if (!this.checkloaded) {
        this.checkloaded = true;
        this.$refs.scroll.refresh();
      }
    },
    handlePlaylist(playlisy) {
      const bottom = playlisy.length > 0 ? '60px' : '';
      this.$refs.recommend.style.bottom = bottom;
      this.$refs.scroll.refresh();
    },
  },
  components: {
    Slider,
    Scroll,
    Loading,
  },
};
</script>
<style scoped lang="stylus">
@import "~common/stylus/variable"
.recommend
  position: fixed
  width: 100%
  top: 88px
  bottom: 0
  .recommend-content
    height: 100%
    overflow: hidden
    .slider-wrapper
      position: relative
      width: 100%
      overflow: hidden
    .recommend-list
      .list-title
        height: 65px
        line-height: 65px
        text-align: center
        font-size: $font-size-medium
        color: $color-theme
      .item
        display: flex
        box-sizing: border-box
        align-items: center
        padding: 0 20px 20px 20px
        .icon
          flex: 0 0 60px
          width: 60px
          padding-right: 20px
          img
            border-radius:10px
        .text
          display: flex
          flex-direction: column
          justify-content: center
          flex: 1
          line-height: 20px
          overflow: hidden
          font-size: $font-size-medium
          .name
            overflow: hidden
            white-space: nowrap;
            text-overflow:ellipsis;
            margin-bottom: 10px
            color: $color-text
          .desc
            overflow: hidden
            white-space: nowrap;
            text-overflow:ellipsis;
            color: $color-text-d
</style>
